import { getprofileAPI } from '@/api/user'
import { routes, resetRouter } from '@/router'

export default {
  namespaced: true,
  state: {
    // 获取服务端的路由规则表
    permission: [],
    // 渲染页码的路由
    dynamiclist: []
  },
  getters: {},
  mutations: {
    setpermission(state, newpermission) {
      state.permission = newpermission
    },
    // 将静态路由和动态路由渲染页面保存到vuex
    setdynamiclist(state, newdynamiclist) {
      state.dynamiclist = [...routes, ...newdynamiclist]
    },
    cleardynamiclist(state) {
      resetRouter()
      state.dynamiclist = []
      state.permission = []
    }
  },
  actions: {
    async getprofile(store) {
      const res = await getprofileAPI()
      // console.log(res)
      store.commit('setpermission', res.data.permissions)
      return res
    }
  }
}
